{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 60,
   "metadata": {
    "pycharm": {
     "is_executing": false
    }
   },
   "outputs": [],
   "source": [
    "import pandas as pd\n",
    "f = open('Task_4_lianjia_sale.csv',encoding='UTF-8') \n",
    "lianjia_data = pd.read_csv(f)\n",
    "f.close()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 61,
   "metadata": {
    "pycharm": {
     "name": "#%%\n"
    }
   },
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "D:\\Anaconda3\\lib\\site-packages\\ipykernel_launcher.py:1: FutureWarning: using a dict on a Series for aggregation\n",
      "is deprecated and will be removed in a future version\n",
      "  \"\"\"Entry point for launching an IPython kernel.\n"
     ]
    },
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>区域平均价格</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>区域</th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>嘉定</th>\n",
       "      <td>36587.687199</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>奉贤</th>\n",
       "      <td>23662.131268</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>宝山</th>\n",
       "      <td>42577.796632</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>徐汇</th>\n",
       "      <td>75395.941983</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>普陀</th>\n",
       "      <td>57943.126871</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "          区域平均价格\n",
       "区域              \n",
       "嘉定  36587.687199\n",
       "奉贤  23662.131268\n",
       "宝山  42577.796632\n",
       "徐汇  75395.941983\n",
       "普陀  57943.126871"
      ]
     },
     "execution_count": 61,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df_avg=lianjia_data.groupby('区域')['价格'].agg({'区域平均价格':'mean'})\n",
    "df_avg.sort_values(by='区域平均价格')\n",
    "df_avg.head()\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 62,
   "metadata": {},
   "outputs": [],
   "source": [
    "from pyecharts.charts import Map,Geo\n",
    "from pyecharts import options as opts"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 69,
   "metadata": {},
   "outputs": [],
   "source": [
    "districts = ['金山区', '奉贤区', '嘉定区', '松江区', '青浦区', '宝山区', '闵行区 ', '浦东新区', '普陀区', '杨浦区', '虹口区', '长宁区', '静安区', '徐汇区', '黄浦区']\n",
    "price=df_avg['区域平均价格'].round(decimals=2).tolist()\n",
    "location_price=[list(i) for i in zip(districts,price)]\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 70,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'C:\\\\Users\\\\78186\\\\Desktop\\\\python_learn\\\\python_learn\\\\crossing_data\\\\map1.html'"
      ]
     },
     "execution_count": 70,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "map_1=Map()\n",
    "map_1.set_global_opts(\n",
    "    title_opts=opts.TitleOpts(title=\"上海各区域平均价格\"),\n",
    "    visualmap_opts=opts.VisualMapOpts(is_show=True, min_=min(price), max_=max(price))  #最大数据范围\n",
    "    )\n",
    "map_1.add(\"上海各区域平均价格\", location_price, maptype=\"上海\")\n",
    "map_1.render('map1.html')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 65,
   "metadata": {},
   "outputs": [],
   "source": [
    "import tushare as ts\n",
    "\n",
    "area_A=ts.get_area_classified()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 66,
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "D:\\Anaconda3\\lib\\site-packages\\ipykernel_launcher.py:1: FutureWarning: using a dict on a Series for aggregation\n",
      "is deprecated and will be removed in a future version\n",
      "  \"\"\"Entry point for launching an IPython kernel.\n"
     ]
    }
   ],
   "source": [
    "area_A_count=area_A.groupby('area')['name'].agg({'各省份上市公司数量':'count'})"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 67,
   "metadata": {},
   "outputs": [],
   "source": [
    "location=area_A_count.index.tolist()\n",
    "a_count=area_A_count['各省份上市公司数量'].tolist()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 68,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'C:\\\\Users\\\\78186\\\\Desktop\\\\python_learn\\\\python_learn\\\\crossing_data\\\\map2.html'"
      ]
     },
     "execution_count": 68,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "map_2=Map()\n",
    "map_2.set_global_opts(\n",
    "    title_opts=opts.TitleOpts(title=\"各省份上市公司数量\"),\n",
    "    visualmap_opts=opts.VisualMapOpts(is_show=True, min_=min(a_count), max_=max(a_count))  \n",
    "    )\n",
    "map_2.add(\"\", zip(location,a_count), maptype=\"china\")\n",
    "map_2.render('map2.html')"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.3"
  },
  "pycharm": {
   "stem_cell": {
    "cell_type": "raw",
    "metadata": {
     "collapsed": false
    },
    "source": []
   }
  }
 },
 "nbformat": 4,
 "nbformat_minor": 1
}
